package com.zsl.casuallyheart.contacts;
import java.util.List;

import org.apache.http.entity.StringEntity;

import cn.bmob.im.BmobUserManager;
import cn.bmob.im.bean.BmobChatUser;
import cn.bmob.v3.listener.FindListener;

import com.zsl.casuallyheart.AppBaseActivity;
import com.zsl.casuallyheart.R;

import android.app.Activity;
import android.os.Bundle;
import android.text.TextUtils;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;

/**
 *  通用类
 * @author zsl
 * @date 2014-10-13 上午10:10:13
 * @version v1.5
 */
public class AddContants extends AppBaseActivity{
	/**
	 * 控件
	 */
	private TextView title_tv_add;
	private TextView title_tv_title;
	private TextView tv_search,tv_add,tv_result_name;
	private EditText et_name;
	
	/**
	 * 数据
	 */
	
	public  BmobUserManager bmobUserManager;
	String search_name;
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
		setContentView(R.layout.add_contants);
		bmobUserManager=BmobUserManager.getInstance(this);
		initView();
		tv_search.setOnClickListener(new OnClickListener() {
			
			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				search_name=et_name.getText().toString();
				if (TextUtils.isEmpty(search_name)) {
					showToast("请输入搜索用户名");
				} else {
					search(search_name);
				}
			}
		});
		
	}
	/**
	 * 初始化控件
	 */
	private void initView(){
		tv_search=(TextView) findViewById(R.id.add_contants_tv_search);
		et_name=(EditText) findViewById(R.id.add_contants_et_name);
		tv_add=(TextView) findViewById(R.id.add_contants_tv_add);
		tv_result_name=(TextView) findViewById(R.id.add_contants_tv_result_name);
		
	}
	/**
	 * 初始化数据
	 */
	private void initData(){
		
	}
	//搜索用户
	private void search(String name){
		bmobUserManager.queryUserByName(search_name, new FindListener<BmobChatUser>() {
			
			@Override
			public void onSuccess(List<BmobChatUser> arg0) {
				// TODO Auto-generated method stub
				showToast("搜索完毕");
			}
			
			@Override
			public void onError(int arg0, String arg1) {
				// TODO Auto-generated method stub
				showToast("没有此用户");
			}
		});
	}
	//显示toast
	private void showToast(String content){
		Toast.makeText(this, content, Toast.LENGTH_SHORT).show();	
	}
	
	
	
}
